/* Copyright (c) 2004-2022 peigen.info. All rights reserved. */

package info.peigen.hotpot.common.core.exception;

import info.peigen.hotpot.common.core.enums.Messageable;
import lombok.Getter;
import lombok.Setter;

/**
 * <b>(SystemException)</b>
 * <p>
 * 系统级异常定义。
 * 通常为不可执行或阻断性异常。
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/3/8
 */
@Setter
@Getter
public class SystemException extends RuntimeException implements Messageable {

    private String code = "System";

    public SystemException() {
        super();
    }

    public SystemException(Messageable messageable) {
        super(messageable.message());
        this.code = messageable.code();
    }

    public SystemException(String message) {
        super(message);
    }

    /**
     * @param message            错误消息
     * @param writableStackTrace 是否收集线程栈信息，对于业务明确的异常，请关闭,设置为false为关闭
     */
    public SystemException(String message, boolean writableStackTrace) {
        super(message, null, false, writableStackTrace);
    }

    /**
     * @param code               错误码
     * @param message            错误消息
     * @param writableStackTrace 是否收集线程栈信息，对于业务明确的异常，请关闭,设置为false为关闭
     */
    public SystemException(String code, String message, boolean writableStackTrace) {
        super(message, null, false, writableStackTrace);
        this.code = code;
    }

    public SystemException(String message, Object o, boolean b, boolean writableStackTrace) {
        super();
    }

    public SystemException(String message, Throwable cause) {
        super(message, cause);
    }

    public SystemException(Throwable cause) {
        super(cause);
    }

    public SystemException(String code, String message) {
        super(message);
        this.code = code;
    }

    public SystemException(String code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
    }

    public SystemException(Throwable cause, String code) {
        super(cause);
        this.code = code;
    }

    public SystemException(Messageable messageable, String msg) {
        super(msg);
        this.code = messageable.code();
    }

    public SystemException(Messageable messageable, Throwable cause) {
        super(messageable.message(), cause);
        this.code = messageable.code();
    }

    @Override
    public String code() {
        return this.code;
    }

    @Override
    public String message() {
        return this.getMessage();
    }
}